<?php

namespace JLPay\Services\Trans\Common;

use JLPay\Services\BaseService;
use JLPay\Models\Trans\Common\GetOpenidRequest;
use JLPay\Models\Trans\Common\GetOpenidResponse;

/**
 * 获取OpenID服务
 */
class GetOpenidService extends BaseService
{
    /**
     * 获取API URL
     *
     * @param string $requestClass 请求类名
     * @param string|null $apiPath 接口路径
     * @return string 完整的API URL
     */
    public function getApiUrl(string $requestClass, ?string $apiPath = null): string
    {
        $baseUrl = $this->config->getUrl();
        
        if ($apiPath) {
            return $baseUrl . $apiPath;
        }
        
        // 直接使用Request类中定义的API_URL
        $apiUrl = constant($requestClass . '::API_URL');
        if ($apiUrl) {
            return $baseUrl . $apiUrl;
        }
        
        // 如果没有定义API_URL，使用默认路径
        return $baseUrl . "/open/trans";
    }

    /**
     * 获取OpenID接口
     *
     * @param GetOpenidRequest $request 获取OpenID请求
     * @return GetOpenidResponse 获取OpenID响应结果
     */
    public function getOpenid(GetOpenidRequest $request): GetOpenidResponse
    {
        return $this->post($request, GetOpenidResponse::class);
    }
} 